package com.ahau.springcloudHystrix.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Author xiao hu die
 * @Date 2021/12/19 13:13
 * @Version 1.0
 */
@Service
public class PaymentService {
  public String paymentInfo_OK(Integer id){

      return "线程池是" +   Thread.currentThread().getName() +"paymentInfo_OK"+id +"O(∩_∩)O哈哈~id ";
  }
  /**设置方法过期时间为3秒，3秒之后就跳转到服务降级之后的方法上面*/
  @HystrixCommand(fallbackMethod = "paymentInfo_timeoutHandler",commandProperties= {
          @HystrixProperty(name ="execution.isolation.thread.timeoutInMilliseconds",value = "3000")
  })
  public String paymentInfo_timeout(Integer id){
      /**暂停几秒钟的线程*/
      try {
          TimeUnit.SECONDS.sleep(5);
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
      return "线程是" +Thread.currentThread().getName() +"paymentInfo_timeout" +id +"┭┮﹏┭┮";
  }
  public String paymentInfo_timeoutHandler(Integer id){
      return "线程是" +Thread.currentThread().getName()+"paymentInfo_timeoutHandler"+id +"(#^.^#)"+"系统繁忙或者运行报错，请稍后再试";
  }
}
